﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VK.Casemeet.Links;
using VK.Comm.TransactSql;
using VK.Comm;
using VK.Casemeet.Areas;
using VK.Casemeet.Members;
using System.Data;

namespace VK.Casemeet.Web.Front
{
    public partial class Site : System.Web.UI.MasterPage
    {
        public int provinceID, cityID;
        public string areaName, bodyclass;

        protected void Page_Init(object sender, EventArgs e)
        {
            provinceID = Util.GetRouteDataInt("provinceID");
            cityID = Util.GetRouteDataInt("cityID");
            if (MemberBLL.IsSessionMember())
            {
                lbNickname.Text = MemberBLL.GetSessionMember().Nickname;
                MemberFromLogin.Style["display"] = "none";
                MemberFromOnline.Style["display"] = "block";
            }
            else
            {
                MemberFromLogin.Style["display"] = "block";
                MemberFromOnline.Style["display"] = "none";
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (GetCurrentAreaID() == 0)
            {
                nav.Visible = true;
                area_nav.Visible = false;
                bodyclass = string.Empty;
            }
            else
            {
                nav.Visible = false;
                area_nav.Visible = true;
                bodyclass = "area_body";
            }
            areaName = AreaBLL.GetArea(GetCurrentAreaID()).Name;

            if (!IsPostBack)
            {
                rptLink01.DataSource = LinkBLL.GetLinkList(new List<Condition>(){
                    new Condition { TableName = "Link", FieldName = "Type", ConditionType = ConditionType.NumeralEqual, 
                        ConditionValue = 30, DbType = DbType.Int32 }
                }, "[Link].[Sort]", SortMode.Desc);
                rptLink01.DataBind();

                rptLink02.DataSource = LinkBLL.GetLinkList(new List<Condition>(){
                    new Condition { TableName = "Link", FieldName = "Type", ConditionType = ConditionType.NumeralEqual, 
                        ConditionValue = 31, DbType = DbType.Int32 }
                }, "[Link].[Sort]", SortMode.Desc);
                rptLink02.DataBind();

                rptLink03.DataSource = LinkBLL.GetLinkList(new List<Condition>(){
                    new Condition { TableName = "Link", FieldName = "Type", ConditionType = ConditionType.NumeralEqual, 
                        ConditionValue = 37, DbType = DbType.Int32 }
                }, "[Link].[Sort]", SortMode.Desc);
                rptLink03.DataBind();

                rptLink04.DataSource = LinkBLL.GetLinkList(new List<Condition>(){
                    new Condition { TableName = "Link", FieldName = "Type", ConditionType = ConditionType.NumeralEqual, 
                        ConditionValue = 39, DbType = DbType.Int32 }
                }, "[Link].[Sort]", SortMode.Desc);
                rptLink04.DataBind();

                rptLink05.DataSource = LinkBLL.GetLinkList(new List<Condition>(){
                    new Condition { TableName = "Link", FieldName = "Type", ConditionType = ConditionType.NumeralEqual, 
                        ConditionValue = 38, DbType = DbType.Int32 }
                }, "[Link].[Sort]", SortMode.Desc);
                rptLink05.DataBind();

                rptLink06.DataSource = LinkBLL.GetLinkList(new List<Condition>(){
                    new Condition { TableName = "Link", FieldName = "Type", ConditionType = ConditionType.NumeralEqual, 
                        ConditionValue = 35, DbType = DbType.Int32 }
                }, "[Link].[Sort]", SortMode.Desc);
                rptLink06.DataBind();

                rptLink07.DataSource = LinkBLL.GetLinkList(new List<Condition>(){
                    new Condition { TableName = "Link", FieldName = "Type", ConditionType = ConditionType.NumeralEqual, 
                        ConditionValue = 36, DbType = DbType.Int32 }
                }, "[Link].[Sort]", SortMode.Desc);
                rptLink07.DataBind();

                rptLink08.DataSource = LinkBLL.GetLinkList(new List<Condition>(){
                    new Condition { TableName = "Link", FieldName = "Type", ConditionType = ConditionType.NumeralEqual, 
                        ConditionValue = 33, DbType = DbType.Int32 }
                }, "[Link].[Sort]", SortMode.Desc);
                rptLink08.DataBind();

                rptLink09.DataSource = LinkBLL.GetLinkList(new List<Condition>(){
                    new Condition { TableName = "Link", FieldName = "Type", ConditionType = ConditionType.NumeralEqual, 
                        ConditionValue = 34, DbType = DbType.Int32 }
                }, "[Link].[Sort]", SortMode.Desc);
                rptLink09.DataBind();

                rptLink10.DataSource = LinkBLL.GetLinkList(new List<Condition>(){
                    new Condition { TableName = "Link", FieldName = "Type", ConditionType = ConditionType.NumeralEqual, 
                        ConditionValue = 40, DbType = DbType.Int32 }
                }, "[Link].[Sort]", SortMode.Desc);
                rptLink10.DataBind();
            }
        }

        protected void butLeave_Click(object sender, EventArgs e)
        {
            MemberBLL.Leave();
            MemberFromLogin.Style["display"] = "block";
            MemberFromOnline.Style["display"] = "none";
        }

        public int GetCurrentAreaID()
        {
            int areaID = 0;
            if (cityID == 0)
            {
                areaID = provinceID;
            }
            else
            {
                areaID = cityID;
            }
            return areaID;
        }

        public string GetAreaUrl()
        {
            return provinceID.ToString() + "_" + cityID.ToString();
        }
    }
}